package com.ytjj.common.utils;

import com.alibaba.fastjson.JSON;
import com.ytjj.common.model.request.AliyunMallPVRequest;
import com.ytjj.common.model.request.AliyunMallRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

@Slf4j
public class AliyunMallApiUtil {


    public static void orderPush(AliyunMallRequest request){
//        if (request.getChannelCode()!=null && request.getChannelCode().startsWith("qw-tt")){
//            // 时间转时间戳
//            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//            LocalDateTime localDateTime = LocalDateTime.parse(request.getOrderTime(), formatter);
//            ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.of("Asia/Shanghai"));
//            long orderTimeMillis = zonedDateTime.toInstant().toEpochMilli();
//            String orderTime = String.valueOf(orderTimeMillis);
//
//
//            String sign = null;
//            try {
//                sign = DigestUtils.md5Hex(request.getOrderNo()+key+orderTime);
//            } catch (Exception e) {
//                log.error("签名报错:",e);
//            }
//            Map<String, String> heads = new HashMap<>();
//            heads.put("sign",sign);
//            String result = HttpClientUtil.doPostJson(ORDERURL, JSON.toJSONString(request),heads);
//            log.info("推送结果,{}",result);
//        }
    }

    public static void  pvPush(AliyunMallPVRequest request){
//        if (request.getChannelCode()!=null && request.getChannelCode().startsWith("qw-tt")){
//            // 时间转时间戳
//            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//            LocalDateTime localDateTime = LocalDateTime.parse(request.getCreateTime(), formatter);
//            ZonedDateTime zonedDateTime = localDateTime.atZone(ZoneId.of("Asia/Shanghai"));
//            long createTimeMillis = zonedDateTime.toInstant().toEpochMilli();
//            String createTime = String.valueOf(createTimeMillis);
//
//            String sign = null;
//            try {
//                sign = DigestUtils.md5Hex(key+createTime);
//            } catch (Exception e) {
//                log.error("签名报错:",e);
//            }
//            Map<String, String> heads = new HashMap<>();
//            heads.put("sign",sign);
//            String result = HttpClientUtil.doPostJson(PVURL, JSON.toJSONString(request),heads);
//            log.info("推送结果,{}",result);
//        }
    }
}
